﻿using System;
using System.Collections.Generic;
using System.Data;
using KxParser.Lexer;
using KxParser.Parser.LR;
using KxParser.Parser.LR0;
using System.Linq;

namespace KxParser
{
    public static class KxParserGlobal
    {
		public static char RuleItemSeparator {get{return ' ';}}
        public static string Equalator { get { return " -> "; } }
        public static string Demarkator { get { return "■"; } }
        public static string GrammarStarter { get { return "S'"; } }


        public static string ProductionItemStarter { get { return "STARTER"; } }
        public static string ProductionItemEnder { get { return "ENDER"; } }

        public static string EmptyCell { get { return ""; } }
        public static string ErrorTokenName { get { return "ERROR_TOKEN"; } }

        public static string[] LexerReservedWords { get { return new[] {ErrorTokenName, Ender, Demarkator, TokenNameSeparator}; } }

        public static string[] Terminals { get; set; }

        public static string[] NonTerminals { get; set; }

        public static ProductionItem[] ProductionItems { get; set; }
        public static ProductionItemEx[] ProductionItemsEx { get; set; }

        public static TokenEx[] InputTokens { get; set; }


		public static bool IsNonTerminal(string value)
		{
			var q = NonTerminals.FirstOrDefault(nonTerminal => nonTerminal.Equals(value)) != null;
			return q;
		}

        internal static bool IsTerminalNonterminalDuplicateNames()
        {
            return (from terminal in Terminals
                    from nonTerminal in NonTerminals
                    where terminal.Equals(nonTerminal)
                    select terminal).Any();
        }

        // Ex
        public static string Ender { get { return "$"; } }
        public static string TokenNameSeparator { get { return "÷"; } }
        public static string[] ReservedWords = new[] {Ender};
        internal static int LookaheadLevel;

        public static List<Exception> InternalExceptions = new List<Exception>();

        // Remembered data during parsing procedure
        public static List<StateEx> States = new List<StateEx>();
        public static DataTable TransitionTable;
        public static List<TableAction> TableActions = new List<TableAction>();

        public static void Reset()
        {
            States.Clear();
            TransitionTable = null;
            TableActions.Clear();
        }
    }
}
